package dm.ast.model.gen.factory;

import java.util.ArrayList;
import java.util.List;

/**
 * GROUP BY的复杂度模板设置
 */
public class OrderModelFactory extends BaseModelFactory{
    //根据深度、宽度，返回order by 子句模型
    public static ComplexityModel groupModels(int wid_t , int dep_t){
        List<ComplexityModel> models = new ArrayList<ComplexityModel>();
        if(dep_t != 1){  //目前不考虑order by子句可能为子查询的情况
            throw new AssertionError("OrderByDepth");
        }

        //常规分配
        models.add(modelNormal(wid_t , dep_t));

        return BaseModelFactory.getRanComplexityModel(models);
    }

    //一般情况下，将order by 子句分割为每个宽度为1 的分组项
    private static ComplexityModel modelNormal(int wid_t , int dep_t){
        ComplexityModel model1 = new ComplexityModel(wid_t);
        for (int i = 0; i < model1.count; i++) {
            model1.comps[i].wid_t = 1;
            model1.comps[i].dep_t = 1;
        }

        return model1;
    }
}
